home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2004 #11 / Amiga Plus CD - 2004 - No. 11.iso / AmiSoft / Text / hyper / makeguide2.lha / MakeGuide2 / MakeGuide2.c < prev    next >
C/C++ Source or Header  |  2003-12-15  |  27KB  |  810 lines

  1. #define INTUI_V36_NAMES_ONLY
  2.  
  3. #include <exec/types.h>
  4. #include <exec/libraries.h>
  5. #include <intuition/intuition.h>
  6. #include <intuition/gadgetclass.h>
  7. #include <libraries/gadtools.h>
  8. #include <libraries/asl.h>
  9. #include <libraries/dos.h>
  10. #include <workbench/workbench.h>
  11. #include <workbench/startup.h>
  12.  
  13. #include <clib/alib_protos.h>
  14. #include <clib/exec_protos.h>
  15. #include <clib/asl_protos.h>
  16. #include <clib/graphics_protos.h>
  17. #include <clib/intuition_protos.h>
  18. #include <clib/gadtools_protos.h>
  19. #include <clib/icon_protos.h>
  20. #include <clib/dos_protos.h>
  21.  
  22. #include <stdio.h>
  23. #include <dos.h>
  24. #include <error.h>
  25. #include <stdlib.h>
  26. #include <string.h>
  27. #include <ctype.h>
  28.  
  29. #define MYGAD_PAT       0
  30. #define MYGAD_SOURCE    1
  31. #define MYGAD_SOURCEBUT 2
  32. #define MYGAD_DEST      3
  33. #define MYGAD_DESTBUT   4
  34. #define MYGAD_TEMP      5
  35. #define MYGAD_TEMPBUT   6
  36. #define MYGAD_HEAD      7
  37. #define MYGAD_HEADBUT   8
  38. #define MYGAD_GOBUT     9
  39. #define MYGAD_MSG       10
  40. #define MYGAD_SORT      11
  41. #define MYGAD_LEN       12
  42. #define MYGAD_COLS      13
  43. #define MYGAD_SUBIDX    14
  44. #define MYGAD_ASCCHECK  15
  45.  
  46. #define MAXFILES        1000
  47. #define FILENAMELENGTH  255
  48.  
  49. char tempfilename[FILENAMELENGTH], guidefilename[FILENAMELENGTH];
  50. char headerfilename[FILENAMELENGTH], filepattern[FILENAMELENGTH];
  51. char searchpath[FILENAMELENGTH], currentdir[FILENAMELENGTH];
  52. char messagebuffer[FILENAMELENGTH], indexbuffer[99];
  53. int indexentrylength=17, columns=4;
  54.  
  55. FILE *outfile, *infile, *guidefile, *headerfile;
  56.  
  57. struct FileInfoBlock *FileInfo;
  58. struct DiskObject *DiskObj;
  59. struct WBArg *WBArguments;
  60. struct WBStartup *WBMessage;
  61. struct Window *MyWindow;
  62. struct Gadget *MyGadgets[16];
  63.  
  64. struct TextAttr MyFont = { "topaz.font", 8, 0, 0, };
  65.  
  66. struct Library *IconBase;
  67. struct Library *IntuitionBase;
  68. struct Library *GfxBase;
  69. struct Library *GadToolsBase;
  70. struct Library *AslBase;
  71.  
  72. short SortIndex=TRUE, SubIndex=FALSE, StrictAscii=TRUE;
  73.  
  74. struct NewMenu MyNewMenu[] = {
  75. { NM_TITLE, "Project", 0, 0, 0, 0, },
  76. {  NM_ITEM, "Compile", "C", 0, 0, 0, },
  77. {  NM_ITEM, "Quit", "Q", 0, 0, 0, },
  78. { NM_TITLE, "Help", 0, 0, 0, 0, },
  79. {  NM_ITEM, "Help...", "H", 0, 0, 0, },
  80. {  NM_ITEM, "About...", "A", 0, 0, 0, },
  81. { NM_END, NULL, 0, 0, 0, 0, },};
  82.  
  83. struct TagItem frtags[] =
  84. { ASL_Hail,       (ULONG)"Makeguide v2.0 file request",
  85.   ASL_Height,     180,
  86.   ASL_Width,      300,
  87.   ASL_LeftEdge,   100,
  88.   ASL_TopEdge,    20,
  89.   ASL_OKText,     (ULONG)"OK",
  90.   ASL_CancelText, (ULONG)"Cancel",
  91.   ASL_File,       (ULONG)"",
  92.   ASL_Dir,        (ULONG)"SYS:",
  93.   TAG_DONE };
  94.  
  95. struct EasyStruct MyEasyStruct =
  96. { sizeof(struct EasyStruct),
  97.   0,
  98.   "About MakeGuide v2.0",
  99.   "MakeGuide v2.0 (c)\nCompiles a list of ascii documents\ninto an AmigaGuide file.\nWritten by Jan Klok.",
  100.   "Okay!" };
  101.   
  102. struct EasyStruct HelpEasyStruct =
  103. { sizeof(struct EasyStruct),
  104.   0,
  105.   "MakeGuide v2.0 help",
  106.   "MakeGuide v2.0 (c)\nSorry, there is currently no online help available.\nRefer to the doc file for more information.",
  107.   "I'll do that!" };
  108.   
  109. void ShowMessage(STRPTR message)
  110. { GT_SetGadgetAttrs(MyGadgets[MYGAD_MSG], MyWindow, NULL,
  111.                     GTTX_Text, message, TAG_END);
  112. }
  113.  
  114. void ShowError(STRPTR ErrorMessage)
  115. { GT_SetGadgetAttrs(MyGadgets[MYGAD_MSG], MyWindow, NULL,
  116.                     GTTX_Text, ErrorMessage, TAG_END);
  117.   if(infile) fclose(infile);
  118.   if(outfile) fclose(outfile);
  119.   if(guidefile) fclose(guidefile);
  120.   if(headerfile) fclose(headerfile);
  121.   if(outfile) remove(tempfilename);
  122.   if(FileInfo) free(FileInfo);
  123. }
  124.  
  125. int ProcessFiles(void)
  126. { int error, i, j, k, s;
  127.   extern int errno;
  128.   unsigned char c='\0';
  129.   char *FileNames[MAXFILES];
  130.   short CheckAscii(char);
  131.   
  132.   if(indexentrylength<=0)
  133.   { ShowError("Indexentrylength must be greater than 0!");
  134.     return(5);
  135.   };
  136.   
  137.   if(columns==0)
  138.   { ShowError("Columns must be different from 0!");
  139.     return(5);
  140.   };
  141.   
  142.   error = getcd(0,currentdir);
  143.   if(error!=NULL)
  144.   { ShowError("Couldn't lock current directory!");
  145.     return(5);
  146.   };
  147.  
  148.   if(strlen(searchpath)==0)
  149.   { strcpy(currentdir,searchpath);
  150.     GT_SetGadgetAttrs(MyGadgets[MYGAD_SOURCE], MyWindow, NULL,
  151.                       GTST_String, searchpath, TAG_END);
  152.   }
  153.   error = chdir(searchpath);
  154.   if(error!=NULL)
  155.   { ShowError("Couldn't change to source directory!");
  156.     return(5);
  157.   };
  158.  
  159.   if(strlen(tempfilename)==0)
  160.   { strcpy(tempfilename,"ram:tmp");
  161.     GT_SetGadgetAttrs(MyGadgets[MYGAD_TEMP], MyWindow, NULL,
  162.                       GTST_String, tempfilename, TAG_END);
  163.   }
  164.   outfile = fopen(tempfilename,"w");
  165.   if(outfile==NULL)
  166.   { ShowError("Temporary file could not be opened for output!");
  167.     return(5);
  168.   };
  169.  
  170.   if(strlen(guidefilename)==0)
  171.   { strcpy(guidefilename,"ram:Guide.guide");
  172.     GT_SetGadgetAttrs(MyGadgets[MYGAD_DEST], MyWindow, NULL,
  173.                       GTST_String, guidefilename, TAG_END);
  174.   }
  175.   guidefile = fopen(guidefilename,"w");
  176.   if(guidefile==NULL)
  177.   { ShowError("Output file for guide could not be opened!");
  178.     return(5);
  179.   };
  180.  
  181.   if(strlen(headerfilename)==0) 
  182.   { headerfile=NULL;
  183.     ShowMessage("Using default header...");
  184.   }
  185.   else
  186.   { headerfile = fopen(headerfilename,"r");
  187.     if(headerfile==NULL)
  188.     { ShowError("Headerfile for guide could not be opened!");
  189.       return(5);
  190.     };
  191.   };
  192.   
  193.   FileInfo = malloc(sizeof(struct FileInfoBlock));
  194.   if(FileInfo==NULL)
  195.   { ShowError("Allocation of fileinfoblock failed!");
  196.     return(5);
  197.   };
  198.  
  199.   sprintf(messagebuffer,"Scanning directory %s...",searchpath);
  200.   ShowMessage(messagebuffer);
  201.   if(filepattern==NULL) strcpy("#?",filepattern);
  202.   error = dfind(FileInfo,filepattern,0);
  203.   if(error != NULL)
  204.   { ShowError("No files found for this filefilter!");
  205.     return(5);
  206.   };
  207.   s=0;
  208.  
  209.   while(error==0)
  210.   { if(NULL != strcmp(headerfilename,FileInfo->fib_FileName))
  211.     { FileNames[s] = malloc(strlen(FileInfo->fib_FileName)+1);
  212.       if(FileNames[s]==NULL)
  213.       { ShowError("Memory allocation for filename failed!");
  214.         return(5);
  215.       };
  216.       strcpy(FileNames[s],FileInfo->fib_FileName);
  217.       s++;
  218.       if(s==MAXFILES)
  219.       { ShowError("Sorry, MAXFILES inputfiles is the limit!");
  220.         return(5);
  221.       };
  222.  
  223.       if(error==0)
  224.       { fprintf(outfile,"@node \"%s\" \"%s\"\n",FileInfo->fib_FileName,FileInfo->fib_FileName);
  225.         sprintf(messagebuffer,"Processing file %d:'%s'",s,FileInfo->fib_FileName);
  226.         ShowMessage(messagebuffer);
  227.         infile = fopen(FileInfo->fib_FileName,"r");
  228.         if(infile == NULL)
  229.         { ShowError("Input file could not be opened!");
  230.           return(5);
  231.         };
  232.  
  233.         c = getc(infile);
  234.         while(CheckAscii(c) != NULL)
  235.         { putc(c,outfile);
  236.           c = getc(infile);
  237.         }
  238.       
  239.         if(c != EOF)
  240.         { sprintf(messagebuffer,"'%s' contains binary!",FileInfo->fib_FileName);
  241.           ShowError(messagebuffer);
  242.           return(5);
  243.         }
  244.         fprintf(outfile,"\n@endnode\n\n");
  245.         fclose(infile);
  246.       }
  247.     }
  248.     error = dnext(FileInfo);
  249.   }
  250.  
  251.   if(SortIndex)
  252.   { ShowMessage("Sorting filenames...");
  253.     strsrt(FileNames,s);
  254.   }
  255.   
  256.   ShowMessage("Writing main node...");
  257.   fprintf(guidefile,"@database %s\n\n",guidefilename);
  258.   fprintf(guidefile,"@node main \"%s\"\n",guidefilename);
  259.  
  260.   ShowMessage("Writing header...");
  261.   if (headerfile)
  262.   { c = getc(headerfile);
  263.     while(CheckAscii(c) != NULL)
  264.     { putc(c,guidefile);
  265.       c = getc(headerfile);
  266.     }
  267.     fprintf(guidefile,"\n");
  268.       
  269.     if(c != EOF)
  270.     { ShowError("The header file contains binary!");
  271.       return(5);
  272.     }
  273.   }
  274.   else
  275.   { fprintf(guidefile,"This guide was created using MakeGuide v2.0 by Jan Klok.\n");
  276.     fprintf(guidefile,"This guide contains %d docfiles\n",s);
  277.   }
  278.  
  279.   k=columns;
  280.   for(i=0;i<s;i++)
  281.   { strncpy(indexbuffer,FileNames[i],indexentrylength);
  282.     for(j=strlen(indexbuffer);j<indexentrylength;j++)
  283.       indexbuffer[j]=' ';
  284.     indexbuffer[j]='\0';
  285.     if(k==columns)
  286.       fprintf(guidefile,"\n   ");
  287.     k--;
  288.     if(k==0)
  289.       k=columns;
  290.     fprintf(guidefile,"@{\"%s\" link \"%s\"}",indexbuffer,FileNames[i]);
  291.     free(FileNames[i]);
  292.   }
  293.   fprintf(guidefile,"\n@endnode\n\n");
  294.   
  295.   fclose(outfile);
  296.   outfile = fopen(tempfilename,"r");
  297.  
  298.   ShowMessage("Writing compiled nodes...");
  299.   c = getc(outfile);
  300.   while(CheckAscii(c) != NULL)
  301.   { putc(c,guidefile);
  302.     c = getc(outfile);
  303.   }
  304.  
  305.   DiskObj=GetDefDiskObject(WBPROJECT);
  306.   DiskObj->do_DefaultTool="AmigaGuide";
  307.   if(DiskObj!=NULL) PutDiskObject(guidefilename,DiskObj);
  308.   
  309.   ShowError("Compilation successfully completed!");
  310.   return(0);
  311. }
  312.  
  313. short CheckAscii(c)
  314. char c;
  315. { short list[]={'\x95','\x97','\x98','\x9c','\x9d','\x9e','\x9f','\xa0',
  316.                 '\xa1','\xa2','\xa3','\xa4','\xa5','\xa6','\xa9','\xaa',
  317.                 '\xab','\xac','\xad','\xaf','\xb0','\xb2','\xb3','\xb4',
  318.                 '\xb7','\xb9','\xba','\xbb','\xbf','\xc0','\xc1','\xc2',
  319.                 '\xc3','\xc4','\xc5','\xca','\xcd','\xce','\xd0','\xd1',
  320.                 '\xd7','\xd8','\xd9','\xda','\xdf','\xe5','\xea','\xee',
  321.                 '\xf0','\xf7','\xf8','\xf9','\x00'};
  322.   short rc;
  323.   int i;
  324.   rc=isascii(c);
  325.   if(!StrictAscii)
  326.   { if(rc==0)
  327.     { for(i=0;list[i]!='\x00';i++)
  328.         if(list[i]==c)
  329.         { rc=c;
  330.           break;
  331.         }
  332.     }
  333.   }
  334.   return(rc);
  335. }
  336.  
  337. void GetWindowContents(void)
  338. { GT_SetGadgetAttrs(MyGadgets[MYGAD_MSG], MyWindow, NULL,
  339.                     GTTX_Text, "Processing files...", TAG_END);
  340.   strcpy(filepattern,((struct StringInfo *)MyGadgets[MYGAD_PAT]->SpecialInfo)->Buffer);
  341.   strcpy(searchpath,((struct StringInfo *)MyGadgets[MYGAD_SOURCE]->SpecialInfo)->Buffer);
  342.   strcpy(guidefilename,((struct StringInfo *)MyGadgets[MYGAD_DEST]->SpecialInfo)->Buffer);
  343.   strcpy(tempfilename,((struct StringInfo *)MyGadgets[MYGAD_TEMP]->SpecialInfo)->Buffer);
  344.   strcpy(headerfilename,((struct StringInfo *)MyGadgets[MYGAD_HEAD]->SpecialInfo)->Buffer);
  345.   indexentrylength=((struct StringInfo *)MyGadgets[MYGAD_LEN]->SpecialInfo)->LongInt;
  346.   columns=((struct StringInfo *)MyGadgets[MYGAD_COLS]->SpecialInfo)->LongInt;
  347.   SortIndex=(MyGadgets[MYGAD_SORT]->Flags & GFLG_SELECTED);
  348.   SubIndex=(MyGadgets[MYGAD_SUBIDX]->Flags & GFLG_SELECTED);
  349.   StrictAscii=(MyGadgets[MYGAD_ASCCHECK]->Flags & GFLG_SELECTED);
  350. }
  351.  
  352. void HandleGadgetEvent(struct Gadget *gad, UWORD code)
  353. { struct FileRequester *fr;
  354.   switch(gad->GadgetID)
  355.   { case MYGAD_SOURCEBUT:
  356.       if(fr=(struct FileRequester *)AllocAslRequest(ASL_FileRequest,frtags));
  357.       { if(AslRequest(fr,NULL))
  358.           GT_SetGadgetAttrs(MyGadgets[MYGAD_SOURCE], MyWindow, NULL,
  359.                             GTST_String, fr->rf_Dir, TAG_END);
  360.         FreeAslRequest(fr);
  361.       }
  362.       break;
  363.     case MYGAD_DESTBUT:
  364.       if(fr=(struct FileRequester *)AllocAslRequest(ASL_FileRequest,frtags));
  365.       { if(AslRequest(fr,NULL))
  366.         { strcpy(guidefilename,fr->rf_Dir);
  367.           AddPart(guidefilename,fr->rf_File,FILENAMELENGTH);
  368.           GT_SetGadgetAttrs(MyGadgets[MYGAD_DEST], MyWindow, NULL,
  369.                             GTST_String, guidefilename, TAG_END);
  370.         }
  371.         FreeAslRequest(fr);
  372.       }
  373.       break;
  374.     case MYGAD_TEMPBUT:
  375.       if(fr=(struct FileRequester *)AllocAslRequest(ASL_FileRequest,frtags));
  376.       { if(AslRequest(fr,NULL))
  377.         { strcpy(tempfilename,fr->rf_Dir);
  378.           AddPart(tempfilename,fr->rf_File,FILENAMELENGTH);
  379.           GT_SetGadgetAttrs(MyGadgets[MYGAD_TEMP], MyWindow, NULL,
  380.                             GTST_String, tempfilename, TAG_END);
  381.         }
  382.         FreeAslRequest(fr);
  383.       }
  384.       break;
  385.     case MYGAD_HEADBUT:
  386.       if(fr=(struct FileRequester *)AllocAslRequest(ASL_FileRequest,frtags));
  387.       { if(AslRequest(fr,NULL))
  388.         { strcpy(headerfilename,fr->rf_Dir);
  389.           AddPart(headerfilename,fr->rf_File,FILENAMELENGTH);
  390.           GT_SetGadgetAttrs(MyGadgets[MYGAD_HEAD], MyWindow, NULL,
  391.                             GTST_String, headerfilename, TAG_END);
  392.         }
  393.         FreeAslRequest(fr);
  394.       }
  395.       break;
  396.     case MYGAD_GOBUT:
  397.       GetWindowContents();
  398.       ProcessFiles();
  399.       break;
  400.   }
  401. }
  402.  
  403. void HandleVanillaKey(UWORD code)
  404. { code=toupper(code);
  405.   switch(code)
  406.   { case 'P':
  407.       ActivateGadget(MyGadgets[MYGAD_PAT], MyWindow, NULL);
  408.       break;
  409.     case 'S':
  410.       ActivateGadget(MyGadgets[MYGAD_SOURCE], MyWindow, NULL);
  411.       break;
  412.     case 'D':
  413.       ActivateGadget(MyGadgets[MYGAD_DEST], MyWindow, NULL);
  414.       break;
  415.     case 'T':
  416.       ActivateGadget(MyGadgets[MYGAD_TEMP], MyWindow, NULL);
  417.       break;
  418.     case 'H':
  419.       ActivateGadget(MyGadgets[MYGAD_HEAD], MyWindow, NULL);
  420.       break;
  421.     case 'C':
  422.       GetWindowContents();
  423.       ProcessFiles();
  424.       break;
  425.     case 'I':
  426.       if(MyGadgets[MYGAD_SORT]->Flags & GFLG_SELECTED)
  427.         GT_SetGadgetAttrs(MyGadgets[MYGAD_SORT], MyWindow, NULL,
  428.                           GTCB_Checked, FALSE, TAG_END);
  429.       else
  430.         GT_SetGadgetAttrs(MyGadgets[MYGAD_SORT], MyWindow, NULL,
  431.                           GTCB_Checked, TRUE, TAG_END);      
  432.       break;
  433.     case 'B':
  434.       if(MyGadgets[MYGAD_SUBIDX]->Flags & GFLG_SELECTED)
  435.         GT_SetGadgetAttrs(MyGadgets[MYGAD_SUBIDX], MyWindow, NULL,
  436.                           GTCB_Checked, FALSE, TAG_END);
  437.       else
  438.         GT_SetGadgetAttrs(MyGadgets[MYGAD_SUBIDX], MyWindow, NULL,
  439.                           GTCB_Checked, TRUE, TAG_END);
  440.       break;
  441.     case 'A':
  442.       if(MyGadgets[MYGAD_ASCCHECK]->Flags & GFLG_SELECTED)
  443.         GT_SetGadgetAttrs(MyGadgets[MYGAD_ASCCHECK], MyWindow, NULL,
  444.                           GTCB_Checked, FALSE, TAG_END);
  445.       else
  446.         GT_SetGadgetAttrs(MyGadgets[MYGAD_ASCCHECK], MyWindow, NULL,
  447.                           GTCB_Checked, TRUE, TAG_END);
  448.       break;
  449.   }
  450. }
  451.  
  452. struct Gadget *CreateAllGadgets(struct Gadget **glistptr, void *VisualInfo)
  453. { struct NewGadget ng;
  454.   struct Gadget *gad;
  455.   
  456.   gad = CreateContext(glistptr);
  457.  
  458.   ng.ng_TopEdge    = 25;
  459.   ng.ng_LeftEdge   = 160;
  460.   ng.ng_Width      = 200;
  461.   ng.ng_Height     = 12;
  462.   ng.ng_GadgetText = "_Pattern";
  463.   ng.ng_TextAttr   = &MyFont;
  464.   ng.ng_VisualInfo = VisualInfo;
  465.   ng.ng_GadgetID   = MYGAD_PAT;
  466.   ng.ng_Flags      = NG_HIGHLABEL;
  467.  
  468.   MyGadgets[MYGAD_PAT] = gad = CreateGadget(STRING_KIND, gad, &ng,
  469.                                           GTST_String, filepattern,
  470.                                           GTST_MaxChars, 50,
  471.                                           GT_Underscore, '_',
  472.                                           TAG_END);
  473.  
  474.   ng.ng_TopEdge   += 15;
  475.   ng.ng_GadgetText = "_Source directory";
  476.   ng.ng_GadgetID   = MYGAD_SOURCE;
  477.  
  478.   MyGadgets[MYGAD_SOURCE] = gad = CreateGadget(STRING_KIND, gad, &ng,
  479.                                              GTST_String, searchpath,
  480.                                              GTST_MaxChars, FILENAMELENGTH - 50,
  481.                                              GT_Underscore, '_',
  482.                                              TAG_END);
  483.  
  484.   ng.ng_LeftEdge  += 220;
  485.   ng.ng_Width      = 40;
  486.   ng.ng_GadgetText = ">>";
  487.   ng.ng_GadgetID   = MYGAD_SOURCEBUT;
  488.  
  489.   MyGadgets[MYGAD_SOURCEBUT] = gad = CreateGadget(BUTTON_KIND, gad, &ng,
  490.                                                 TAG_END);
  491.  
  492.   ng.ng_TopEdge   += 15;
  493.   ng.ng_LeftEdge  -= 220;
  494.   ng.ng_Width      = 200;
  495.   ng.ng_GadgetText = "_Destination";
  496.   ng.ng_GadgetID   = MYGAD_DEST;
  497.  
  498.   MyGadgets[MYGAD_DEST] = gad = CreateGadget(STRING_KIND, gad, &ng,
  499.                                            GTST_String, guidefilename,
  500.                                            GTST_MaxChars, FILENAMELENGTH,
  501.                                            GT_Underscore, '_',
  502.                                            TAG_END);
  503.   ng.ng_LeftEdge  += 220;
  504.   ng.ng_Width      = 40;
  505.   ng.ng_GadgetText = ">>";
  506.   ng.ng_GadgetID   = MYGAD_DESTBUT;
  507.  
  508.   MyGadgets[MYGAD_DESTBUT] = gad = CreateGadget(BUTTON_KIND, gad, &ng,
  509.                                               TAG_END);
  510.  
  511.   ng.ng_TopEdge   += 15;
  512.   ng.ng_LeftEdge  -= 220;
  513.   ng.ng_Width      = 200;
  514.   ng.ng_GadgetText = "_Temporary file";
  515.   ng.ng_GadgetID   = MYGAD_TEMP;
  516.  
  517.   MyGadgets[MYGAD_TEMP] = gad = CreateGadget(STRING_KIND, gad, &ng,
  518.                                            GTST_String, tempfilename,
  519.                                            GTST_MaxChars, FILENAMELENGTH,
  520.                                            GT_Underscore, '_',
  521.                                            TAG_END);
  522.   ng.ng_LeftEdge  += 220;
  523.   ng.ng_Width      = 40;
  524.   ng.ng_GadgetText = ">>";
  525.   ng.ng_GadgetID   = MYGAD_TEMPBUT;
  526.  
  527.   MyGadgets[MYGAD_TEMPBUT] = gad = CreateGadget(BUTTON_KIND, gad, &ng,
  528.                                               TAG_END);
  529.  
  530.   ng.ng_TopEdge   += 15;
  531.   ng.ng_LeftEdge  -= 220;
  532.   ng.ng_Width      = 200;
  533.   ng.ng_GadgetText = "_Header file";
  534.   ng.ng_GadgetID   = MYGAD_HEAD;
  535.  
  536.   MyGadgets[MYGAD_HEAD] = gad = CreateGadget(STRING_KIND, gad, &ng,
  537.                                            GTST_String, headerfilename,
  538.                                            GTST_MaxChars, FILENAMELENGTH,
  539.                                            GT_Underscore, '_',
  540.                                            TAG_END);
  541.   ng.ng_LeftEdge  += 220;
  542.   ng.ng_Width      = 40;
  543.   ng.ng_GadgetText = ">>";
  544.   ng.ng_GadgetID   = MYGAD_HEADBUT;
  545.  
  546.   MyGadgets[MYGAD_HEADBUT] = gad = CreateGadget(BUTTON_KIND, gad, &ng,
  547.                                               TAG_END);
  548.  
  549.   ng.ng_TopEdge   += 15;
  550.   ng.ng_LeftEdge  -= 220;
  551.   ng.ng_Width      = 40;
  552.   ng.ng_GadgetText = "Index entry _length";
  553.   ng.ng_GadgetID   = MYGAD_LEN;
  554.  
  555.   MyGadgets[MYGAD_LEN] = gad = CreateGadget(INTEGER_KIND, gad, &ng,
  556.                                            GTIN_Number, indexentrylength,
  557.                                            GTIN_MaxChars, 2,
  558.                                            GT_Underscore, '_',
  559.                                            TAG_END);
  560.   ng.ng_LeftEdge  += 220;
  561.   ng.ng_GadgetText = "Index entry _columns";
  562.   ng.ng_GadgetID   = MYGAD_COLS;
  563.  
  564.   MyGadgets[MYGAD_COLS] = gad = CreateGadget(INTEGER_KIND, gad, &ng,
  565.                                            GTIN_Number, columns,
  566.                                            GTIN_MaxChars, 1,
  567.                                            GT_Underscore, '_',
  568.                                            TAG_END);
  569.   ng.ng_TopEdge   += 15;
  570.   ng.ng_LeftEdge  -= 220;
  571.   ng.ng_Width      = 200;
  572.   ng.ng_Height     = 20;
  573.   ng.ng_GadgetText = "Sort _index";
  574.   ng.ng_GadgetID   = MYGAD_SORT;
  575.  
  576.   MyGadgets[MYGAD_SORT] = gad = CreateGadget(CHECKBOX_KIND, gad, &ng,
  577.                                            GTCB_Checked, SortIndex,
  578.                                            GT_Underscore, '_',
  579.                                            TAG_END);
  580.   ng.ng_LeftEdge  += 220;
  581.   ng.ng_Width      = 200;
  582.   ng.ng_Height     = 20;
  583.   ng.ng_GadgetText = "Create su_bindex";
  584.   ng.ng_GadgetID   = MYGAD_SUBIDX;
  585.  
  586.   MyGadgets[MYGAD_SUBIDX] = gad = CreateGadget(CHECKBOX_KIND, gad, &ng,
  587.                                            GTCB_Checked, SubIndex,
  588.                                            GT_Underscore, '_',
  589.                                            GA_Disabled, TRUE,
  590.                                            TAG_END);
  591.   ng.ng_TopEdge   += 15;
  592.   ng.ng_LeftEdge  -= 220;
  593.   ng.ng_Width      = 200;
  594.   ng.ng_Height     = 20;
  595.   ng.ng_GadgetText = "Strict _ascii check";
  596.   ng.ng_GadgetID   = MYGAD_ASCCHECK;
  597.  
  598.   MyGadgets[MYGAD_ASCCHECK] = gad = CreateGadget(CHECKBOX_KIND, gad, &ng,
  599.                                            GTCB_Checked, StrictAscii,
  600.                                            GT_Underscore, '_',
  601.                                            TAG_END);
  602.   ng.ng_TopEdge   += 15;
  603.   ng.ng_GadgetText = "_Compile";
  604.   ng.ng_GadgetID   = MYGAD_GOBUT;
  605.  
  606.   MyGadgets[MYGAD_GOBUT] = gad = CreateGadget(BUTTON_KIND, gad, &ng,
  607.                                             GT_Underscore, '_',
  608.                                             TAG_END);
  609.   ng.ng_TopEdge   += 33;
  610.   ng.ng_LeftEdge   = 5;
  611.   ng.ng_Width      = 455;
  612.   ng.ng_Height     = 12;
  613.   ng.ng_GadgetText = "";
  614.   ng.ng_GadgetID   = MYGAD_MSG;
  615.  
  616.   MyGadgets[MYGAD_MSG] = gad = CreateGadget(TEXT_KIND, gad, &ng,
  617.                                           GTTX_Text, "Ready when you are!",
  618.                                           GTTX_Border, TRUE,
  619.                                           TAG_END);
  620.    return(gad);
  621. }
  622.  
  623. void ProcessWindowEvents(struct Menu *MenuStrip)
  624. { struct IntuiMessage *imsg;
  625.   ULONG imsgClass;
  626.   UWORD imsgCode;
  627.   UWORD menuNumber;
  628.   UWORD menuNum;
  629.   UWORD itemNum;
  630.   UWORD subNum;
  631.   struct MenuItem *item;
  632.   struct Gadget *gad;
  633.   BOOL terminated = FALSE;
  634.   
  635.   while(!terminated)
  636.   { Wait(1 << MyWindow->UserPort->mp_SigBit);
  637.     while((!terminated) && (imsg=GT_GetIMsg(MyWindow->UserPort)))
  638.     { gad = (struct Gadget *)imsg->IAddress;
  639.       imsgClass = imsg->Class;
  640.       imsgCode = imsg->Code;
  641.       GT_ReplyIMsg(imsg);
  642.       switch(imsgClass)
  643.       {  case IDCMP_GADGETDOWN:
  644.          case IDCMP_MOUSEMOVE:
  645.          case IDCMP_GADGETUP:
  646.            HandleGadgetEvent(gad, imsgCode);
  647.            break;
  648.          case IDCMP_VANILLAKEY:
  649.            HandleVanillaKey(imsgCode);
  650.            break;
  651.          case IDCMP_CLOSEWINDOW:
  652.            terminated=TRUE;
  653.            break;
  654.          case IDCMP_REFRESHWINDOW:
  655.            GT_BeginRefresh(MyWindow);
  656.            GT_EndRefresh(MyWindow,TRUE);
  657.            break;
  658.          case IDCMP_MENUPICK:
  659.            menuNumber = imsg->Code;
  660.            while((menuNumber != MENUNULL) && (!terminated))
  661.            { item = ItemAddress(MenuStrip, menuNumber);
  662.              menuNum = MENUNUM(menuNumber);
  663.              itemNum = ITEMNUM(menuNumber);
  664.              subNum = SUBNUM(menuNumber);
  665.  
  666.              if((menuNum == 0) && (itemNum == 0))
  667.                ProcessFiles();
  668.              if((menuNum == 0) && (itemNum == 1))
  669.                terminated=TRUE;
  670.              if((menuNum == 1) && (itemNum == 0))
  671.                EasyRequest(NULL,&HelpEasyStruct,NULL);
  672.              if((menuNum == 1) && (itemNum == 1))
  673.                EasyRequest(NULL,&MyEasyStruct,NULL);
  674.  
  675.              menuNumber=item->NextSelect;
  676.            }
  677.            break;
  678.       }
  679.     }
  680.   }
  681. }
  682.  
  683. void OpenGadToolsWindow(void)
  684. { struct TextFont *Font;
  685.   struct Screen *MyScreen;
  686.   struct Gadget *GadgetList;
  687.   void *VisualInfo;
  688.   struct Menu *MenuStrip;
  689.   
  690.   if(NULL==(Font=OpenFont(&MyFont)))
  691.     ShowError("Failed to open topaz 80");
  692.   else
  693.   { if(NULL==(MyScreen = LockPubScreen(NULL)))
  694.       ShowError("Couldn't lock default public screen");
  695.     else
  696.     { if(NULL==(VisualInfo = GetVisualInfo(MyScreen, TAG_END)))
  697.         ShowError("GetVisualInfo() failed");
  698.       else
  699.       { if(NULL==CreateAllGadgets(&GadgetList, VisualInfo))
  700.           ShowError("CreateAllGadgets() failed");
  701.         else
  702.         { if(NULL==(MyWindow=OpenWindowTags(NULL,
  703.                       WA_Title, "MakeGuide v2.0",
  704.                       WA_Gadgets, GadgetList,
  705.                       WA_AutoAdjust, TRUE,
  706.                       WA_Width, 465,
  707.                       WA_InnerHeight, 180,
  708.                       WA_DragBar, TRUE,
  709.                       WA_DepthGadget, TRUE,
  710.                       WA_Activate, TRUE,
  711.                       WA_CloseGadget, TRUE,
  712.                       WA_SimpleRefresh, TRUE,
  713.                       WA_IDCMP, IDCMP_CLOSEWINDOW |
  714.                                 IDCMP_REFRESHWINDOW |
  715.                                 IDCMP_VANILLAKEY |
  716.                                 SLIDERIDCMP |
  717.                                 STRINGIDCMP |
  718.                                 BUTTONIDCMP |
  719.                                 IDCMP_MENUPICK,
  720.                       WA_PubScreen, MyScreen,
  721.                       TAG_END)))
  722.             ShowError("OpenWindow() failed");
  723.           else
  724.           { /* Now we can attach the menustrip */
  725.             if(NULL==(MenuStrip=CreateMenus(MyNewMenu, TAG_END)))
  726.               ShowError("Couldn't create menu");
  727.             else
  728.             { if(NULL==(LayoutMenus(MenuStrip,VisualInfo,TAG_END)))
  729.                 ShowError("Couldn't layout menus");
  730.               else
  731.               { if(NULL==(SetMenuStrip(MyWindow, MenuStrip)))
  732.                   ShowError("Couldn't set menustrip");
  733.                 else
  734.                 { GT_RefreshWindow(MyWindow, NULL);
  735.                   ProcessWindowEvents(MenuStrip);
  736.                   CloseWindow(MyWindow);
  737.                 }
  738.               }
  739.               FreeGadgets(GadgetList);
  740.               FreeVisualInfo(VisualInfo);
  741.             }
  742.             UnlockPubScreen(NULL, MyScreen);
  743.           }
  744.           CloseFont(Font);
  745.         }
  746.       }
  747.     }
  748.   }
  749. }    
  750.  
  751. main(int argc, char **argv)
  752. { char *toolvalue=NULL;
  753.   if(argc != 0)
  754.   { printf("\nMakeGuide v2.0 - by Jan Klok\n");
  755.     printf("Run me from Workbench\n\nValid tooltypes are:\n");
  756.     printf("FILEFILTER=<wildcard>\n");
  757.     printf("SOURCEDIR=<directory>\n");
  758.     printf("DESTINATION=<filename>\n");
  759.     printf("TEMPFILE=<filename>\n");
  760.     printf("HEADERFILE=<filename>\n");
  761.     printf("Refer to the doc file for more information.\n");
  762.   }
  763.   else
  764.   { if(NULL==(IconBase=OpenLibrary("icon.library", 37)))
  765.       ShowError("Requires v37 icon.library");
  766.     else
  767.     { if(NULL==(IntuitionBase=OpenLibrary("intuition.library", 37)))
  768.         ShowError("Requires v37 intuition.library");
  769.       else
  770.       { if(NULL==(GfxBase=OpenLibrary("graphics.library",37)))
  771.           ShowError("Requires v37 graphics.library");
  772.         else
  773.         { if(NULL==(GadToolsBase=OpenLibrary("gadtools.library", 37)))
  774.             ShowError("Requires v37 intuition.library");
  775.           else
  776.           { if(NULL==(AslBase=OpenLibrary("asl.library", 37)))
  777.               ShowError("Requires v37 asl.library");
  778.             else
  779.             { WBMessage=(struct WBStartup *)argv;
  780.               WBArguments=WBMessage->sm_ArgList;
  781.               DiskObj = GetDiskObject(WBArguments->wa_Name);
  782.               strcpy(filepattern,FindToolType(DiskObj->do_ToolTypes,"FILEFILTER"));
  783.               strcpy(searchpath,FindToolType(DiskObj->do_ToolTypes,"SOURCEDIR"));
  784.               strcpy(guidefilename,FindToolType(DiskObj->do_ToolTypes,"DESTINATION"));
  785.               strcpy(tempfilename,FindToolType(DiskObj->do_ToolTypes,"TEMPFILE"));
  786.               strcpy(headerfilename,FindToolType(DiskObj->do_ToolTypes,"HEADERFILE"));
  787.               toolvalue=(char *)FindToolType(DiskObj->do_ToolTypes,"STRICTASCII");
  788.               if(MatchToolValue(toolvalue,"YES")) StrictAscii=TRUE;
  789.               if(MatchToolValue(toolvalue,"NO")) StrictAscii=FALSE;
  790.               toolvalue=(char *)FindToolType(DiskObj->do_ToolTypes,"SORTINDEX");
  791.               if(MatchToolValue(toolvalue,"YES")) SortIndex=TRUE;
  792.               if(MatchToolValue(toolvalue,"NO")) SortIndex=FALSE;
  793.               toolvalue=(char *)FindToolType(DiskObj->do_ToolTypes,"SUBINDEX");
  794.               if(MatchToolValue(toolvalue,"YES")) SubIndex=TRUE;
  795.               if(MatchToolValue(toolvalue,"NO")) SubIndex=FALSE;
  796.                 
  797.               OpenGadToolsWindow();
  798.               FreeDiskObject(DiskObj);
  799.               CloseLibrary(AslBase);
  800.             }
  801.           }
  802.           CloseLibrary(GadToolsBase);
  803.         }
  804.         CloseLibrary(GfxBase);
  805.       }
  806.       CloseLibrary(IntuitionBase);
  807.     }
  808.     CloseLibrary(IconBase);
  809.   } 
  810. }